let timer = null
let speed = 0.5 * 1000

const diff = () => {
    const box = document.querySelector('#box')
    const ch = box.children
    const map = {}
    for (let i = 0; i < ch.length; i++) {
        const color = ch[i].style.backgroundColor
        map[color] ? map[color].push(ch[i]) : map[color] = [ch[i]]
        if (i > 1) {
            for (let k in map) {
                if (map[k].length == 1) {
                    map[k][0].click()
                    return
                }
            }
            // console.log(map)
        }
    }
}

const beginDiff = () => {
    timer = setInterval(diff, speed)
}

const stopDiff = () => {
    clearInterval(timer)
}
